﻿#ifndef ONCE_TRIGGER_THREAD_H
#define ONCE_TRIGGER_THREAD_H

#include "libdaq/device/base_device.h"
#include <thread>
#include <vector>
#include <atomic>
#include <chrono>
#include <memory>
#include <iostream>
#include <condition_variable>

class OnceTriggerADCThread
{
public:
  OnceTriggerADCThread(std::shared_ptr<libdaq::device::LockzhinerBaseDevice> base_device,
                      int channel,
                      std::vector<float>& data)
      : base_device_(base_device),
        channel_(channel),
        data_(data),
        thread_is_running_(false) {}

  void start();
  void quit();
  void run();
  bool thread_is_running();

  void setThread_is_running(bool newThread_is_running);

protected:
  bool CheckDataEmpty();

private:
  int channel_;
  std::vector<float>& data_;
  std::weak_ptr<libdaq::device::LockzhinerBaseDevice> base_device_;
  std::atomic<bool> thread_is_running_;
  std::thread thread_;

  int total_data_length_;
  int timeout_msec_;

  std::mutex mutex_;
  std::condition_variable cv_;
};

#endif // ONCE_TRIGGER_THREAD_H
